package com.hd.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.dao.DataAccessException;

import com.hd.common.DataPage;
import com.hd.persistence.dao.ConstantsDao;
import com.hd.persistence.dao.MachineDao;
import com.hd.persistence.dao.PersonDao;
import com.hd.persistence.model.Constants;
import com.hd.persistence.model.Machine;
import com.hd.persistence.model.Person;
import com.hd.service.MemberManager;
import com.hd.utils.HdException;


public class MemberManagerImpl implements MemberManager {
	private ConstantsDao constantsDao;
	private MachineDao machineDao;
	private PersonDao personDao;
	
	////////////////////常量////////////////////
	
	public void saveConstants(Constants constants) throws HdException {
		try {
			constantsDao.save(constants);
		} catch (DataAccessException e) {
			throw new HdException(e.getMessage());
		}
	}
	
	public void deleteConstants(Long constantsId) throws HdException {
		try {
			constantsDao.removeById(constantsId);
		} catch (DataAccessException e) {
			throw new HdException(e.getMessage());
		}
	}
	
	public Constants getConstants(Long constantsId) throws HdException {
		try {
			return constantsDao.get(constantsId);
		} catch (DataAccessException e) {
			throw new HdException(e.getMessage());
		}
	}
	
	////////////////////机器////////////////////
	
	public void saveMachine(Machine machine) throws HdException {
		try {
			machineDao.save(machine);
		} catch (DataAccessException e) {
			throw new HdException(e.getMessage());
		}
	}
	
	public void deleteMachine(Long machineId) throws HdException {
		try {
			machineDao.removeById(machineId);
		} catch (DataAccessException e) {
			throw new HdException(e.getMessage());
		}
	}
	
	public Machine getMachine(Long machineId) throws HdException {
		try {
			return machineDao.get(machineId);
		} catch (DataAccessException e) {
			throw new HdException(e.getMessage());
		}
	}
	
	public DataPage<Machine> pageQueryMachines(int pageNo, int pageSize) throws HdException {
		try {
			return machineDao.pageQueryMachines(pageNo, pageSize);
		} catch (DataAccessException e) {
			throw new HdException(e.getMessage());
		}
	}
	
	public List<Machine> listMachine() throws HdException{
		try {
			return machineDao.listMachine();
		} catch (DataAccessException e) {
			throw new HdException(e.getMessage());
		}
	}
	
	public DataPage<Machine> pageQueryMachines(int category,int pageNo, int pageSize) throws HdException{
		try {
			return machineDao.pageQueryMachines(category,pageNo, pageSize);
		} catch (DataAccessException e) {
			throw new HdException(e.getMessage());
		}
	}
	
	////////////////////人员////////////////////
	
	public void savePerson(Person person) throws HdException {
		try {
			personDao.save(person);
		} catch (DataAccessException e) {
			throw new HdException(e.getMessage());
		}
	}
	
	public void deletePerson(Long personId) throws HdException {
		try {
			personDao.removeById(personId);
		} catch (DataAccessException e) {
			throw new HdException(e.getMessage());
		}
	}
	
	public Person getPerson(Long personId) throws HdException {
		try {
			return personDao.get(personId);
		} catch (DataAccessException e) {
			throw new HdException(e.getMessage());
		}
	}
	
	public DataPage<Person> pageQueryPerson(int pageNo, int pageSize) throws HdException {
		try {
			return personDao.pageQueryPersons(pageNo, pageSize);
		} catch (DataAccessException e) {
			throw new HdException(e.getMessage());
		}
	}
	
	public DataPage<Person> pageQueryPerson(String name, Date beginTime, int pageNo, int pageSize) throws HdException {
		try {
			return personDao.pageQueryPersons(name, beginTime, pageNo, pageSize);
		} catch (DataAccessException e) {
			throw new HdException(e.getMessage());
		}
	}
	
	@Override
	public List<Person> listPerson(int category,boolean isAdmin) throws HdException {
		try {
			return personDao.listPerson(category,isAdmin);
		} catch (DataAccessException e) {
			throw new HdException(e.getMessage());
		}
	}
	
	public Person findPersonBy(String loginId, String password) throws HdException {
		try {
			return personDao.findPersonBy(loginId, password);
		} catch (DataAccessException e) {
			throw new HdException(e.getMessage());
		}
	}

	
	////////////////////getter、setter////////////////////
	
	public ConstantsDao getConstantsDao() {
		return constantsDao;
	}
	public void setConstantsDao(ConstantsDao constantsDao) {
		this.constantsDao = constantsDao;
	}
	public MachineDao getMachineDao() {
		return machineDao;
	}
	public void setMachineDao(MachineDao machineDao) {
		this.machineDao = machineDao;
	}
	public PersonDao getPersonDao() {
		return personDao;
	}
	public void setPersonDao(PersonDao personDao) {
		this.personDao = personDao;
	}

	
	
	
}
